<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>通过 flex 布局实现</title>
  <style>
      .outer {
          width: 300px;
          height: 300px;
          padding: 20px;
          background: #ccc;

          display: flex;
          /* 居中对齐 */
          justify-content: center;
          /* 上下对齐 */
          align-items: center;
      }

      .box {
          width: 50%;
          background: red;
          /* 此时的百分比 是按照父元素宽度而言的 */
          padding-bottom: 50%;
      }
  </style>
</head>
<body>
<div class="outer">
  <div class="box"></div>
</div>
</body>
</html>
